﻿using System;
using System.Collections.Generic;
using System.Configuration;

namespace Wusong.Gold.DataService
{
    class Program
    {
        private static int counter = 0;
        private static IList<IWriterBase> writList = new List<IWriterBase>();

        static void Main(string[] args)
        {

            //IWriterBase write = new PlainTextWriter(null);
            string connecStr = System.Configuration.ConfigurationManager.ConnectionStrings["Connection String"].ConnectionString;
            IWriterBase dataWrite = new DataBaseWriter(connecStr);
            //writList.Add(write);
            writList.Add(dataWrite);

            ZJWResource resource = new ZJWResource();
            using (ReaderBase reader = new ReaderBase(resource))
            {
                Console.WriteLine("start read");
                Console.WriteLine("press q to quit");
                reader.AfterRead += OnAfterRead;
                reader.AfterRead += Count;
                reader.Start();
                while (Console.Read() != 'q') //直到按小写字母q退出,否则一直抓取下去
                {

                }
            }
        }

        public static void OnAfterRead(object sender, ReadEventArgs args)
        {
            if (writList != null && writList.Count > 0)
            {
                foreach (IWriterBase writer in writList)
                {
                    writer.Write(args.Value);
                }
            }
        }

        public static void Count(object sender, ReadEventArgs args)
        {
            counter++;
            Console.WriteLine(counter.ToString());
        }

    }

}
